package com.fhz.a2102high6.test5

import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*

/**
 * 时间:2023/9/15
 * @author Mr.Feng
 * 简述: TODO
 */
fun main() = runBlocking {

    val list = listOf<String>("1","2")
    list.asFlow().collect{
//        println(it)
    }

    flowOf(1,2,3).map {
        "$it Hi"
    }.filter {
        it == "1 Hi"
    }.catch {
        emit("1")
    }.collect{
        println(it)
    }



//    println("开始收集")
//    delay(1000)
//    createFlow().collect {
//        println(it)
//    }


}

fun createFlow(): Flow<Int> = channelFlow {

    withContext(Dispatchers.IO){
        send(0)
    }
    println("开始发送")
    send(1)

}
